﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Licenta1.Shapes;

namespace Licenta1.Statements
{
    class DrawStatement:Statement
    {
        Expression Params;

        public DrawStatement(Context context, Expression parameters)
            : base(context)
        {
            Params = parameters;
        }

        public override void Execute()
        {
            //Console.WriteLine("Draw apelat.. In rand culoarea: " + context.mp.rand.COLOR);
            if (Params == null)
                Console.WriteLine("Nothing to display..... ");
            else
            {
                try
                {
                    ParameterList p_list = (ParameterList)Params;

                    Draw(p_list);
                }
                catch (Exception)
                {
                    try
                    {
                        Shape s = (Shape)(Params.Value);
                        s.Draw();
                    }
                    catch (Exception e) { Console.WriteLine("Exception: " + e.Message); }
                }
            }
        }

        public void Draw(ParameterList list)
        {
            if (list.FirstValue != null)
            {
                try { ((Shape)list.FirstValue).Draw(); }
                catch (Exception e) { Console.WriteLine("Exception: " + e.Message); }
            }
            if (list.SecondValue != null)
                if (list.SecondValue.GetType() != typeof(ParameterList))
                {
                    try { ((Shape)list.SecondValue).Draw(); }
                    catch (Exception e) { Console.WriteLine("Exception: " + e.Message); }
                }
                else Draw((ParameterList)list.SecondValue);
        }
    }
}
